package java67_17.jiekou.pc;

public class MainBoard {
	private String name;
	private CPU cpu;// 插槽
	private Memory mem;// 内存插槽
	// 4个usb插口
	private USB[] usbs = new USB[4];

	public MainBoard(String n) {
		name = n;
	}

	/**
	 * 模拟电脑开始工作
	 */
	public void work() {
		System.out.println("主板是:" + name);
		System.out.println("cpu开始:");
		cpu.calculate();
		System.out.println("内存开始:");
		mem.work();
		for (int i = 0; i < usbs.length; i++) {
			if (usbs[i] != null)
				usbs[i].work();
		}
	}

	// 安装cpu
	public void assembleCPU(CPU c) {
		this.cpu = c;
	}

	// 安装内存
	public void installMem(Memory m) {
		this.mem = m;
	}

	// 插上usb设备
	public void installUSB(USB u) {
		for (int i = 0; i < usbs.length; i++) {
			if (usbs[i] == null) {
				usbs[i] = u;
				usbs[i].plug();
				return;
			}
		}
	}
}
